package com.stylefeng.guns.base;

import com.alibaba.fastjson.JSONObject;
import com.stylefeng.guns.rest.GunsRestApplication;
import com.stylefeng.guns.rest.modular.artitle.controller.dto.AccessRequest;
import com.stylefeng.guns.rest.modular.artitle.controller.dto.ArtitleBodyRequest;
import com.stylefeng.guns.rest.modular.attent.controller.dto.AttentHotRequest;
import com.stylefeng.guns.rest.modular.auth.controller.dto.AuthRequest;
import com.stylefeng.guns.rest.modular.catalogy.controller.dto.AllListRequest;
import com.stylefeng.guns.rest.modular.catalogy.controller.dto.ArticleRequest;
import com.stylefeng.guns.rest.modular.catalogy.controller.dto.CatalogyListRequest;
import com.stylefeng.guns.rest.modular.content.controller.dto.AddContentRequest;
import com.stylefeng.guns.rest.modular.content.controller.dto.CommentListRequest;
import com.stylefeng.guns.rest.modular.jubao.controller.dto.JubaoRequest;
import com.stylefeng.guns.rest.modular.keyword.controller.dto.KeywordRequestBody;
import com.stylefeng.guns.rest.modular.sms.controller.dto.SmsCodeGetRequest;
import com.stylefeng.guns.rest.modular.users.controller.dto.UpdateInfoRequest;
import com.stylefeng.guns.rest.modular.users.controller.dto.UserInfoRequest;
import com.stylefeng.guns.rest.modular.users.controller.dto.UserRegisterParam;
import com.stylefeng.guns.rest.modular.version.controller.dto.VersionRequest;
import com.stylefeng.guns.rest.modular.viewrecord.controller.dto.RecordListRequest;
import com.stylefeng.guns.rest.modular.viewrecord.controller.dto.ShareRecordRequest;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;


/**
 * 基础测试类
 *
 * @author stylefeng
 * @Date 2017/5/21 16:10
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = GunsRestApplication.class)
@WebAppConfiguration
//@Transactional //打开的话测试之后数据可自动回滚
public class BaseJunit {

    @Autowired
    WebApplicationContext webApplicationContext;

    protected MockMvc mockMvc;

    @Before
    public void setupMockMvc(){
        mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
    }

    @Before
    public void initDatabase(){
    }
    @Test
    public void test(){
        VersionRequest request = new VersionRequest();
    	String param_json = JSONObject.toJSONString(request);
    	try {
			mockMvc.perform(post("/version/getVersionIos").contentType(MediaType.APPLICATION_JSON).content(param_json)).andDo(print()).andReturn();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
}
